net/tftp: Fix stack buffer overflow in tftp_open()
authorB Horn <b@horn.uk>
Thu, 18 Apr 2024 16:32:34 +0000 (17:32 +0100)
committerFelix Zielcke <fzielcke@z-51.de>
Thu, 3 Jul 2025 16:35:51 +0000 (18:35 +0200)
commit38e01ec9131aeb00d0048c67a27a58e724d055f2
tree862c2e8b84c83f477a0f18d9c5370d4d0b6768d5
parent7297a2ab4d58ac449f4f1ca5c362651291019275
net/tftp: Fix stack buffer overflow in tftp_open()

An overly long filename can be passed to tftp_open() which would cause
grub_normalize_filename() to write out of bounds.

Fixed by adding an extra argument to grub_normalize_filename() for the
space available, making it act closer to a strlcpy(). As several fixed
strings are strcpy()'d after into the same buffer, their total length is
checked to see if they exceed the remaining space in the buffer. If so,
return an error.

On the occasion simplify code a bit by removing unneeded rrqlen zeroing.

Reported-by: B Horn <b@horn.uk>
Signed-off-by: B Horn <b@horn.uk>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Gbp-Pq: Topic cve-2025-jan
Gbp-Pq: Name net-tftp-Fix-stack-buffer-overflow-in-tftp_open.patch
grub-core/net/tftp.c